Swanson CMS
Module Overview


While the module system at first glance seems compilcated, creating a module for Swanson CMS is actually quite easy.

This is a guide to writing a simple Module.
It should be first noted, that each module is based on categories. Sometimes, a module can share categories with
another module, but each module needs a category to work.

Here we are going to make a basic "Hello World" module.

First create a file and name it helloworld.php
Inside the file insert the following:
<?
echo "Hello World";
?>

Save the file and upload it into the modules folder.

Now, we need to create the install SQL code.

INSERT INTO `modules` ( 
`id` ,
`needscat` ,
`tag` ,
`load` ,
`adminload` ,
`name` ,
`showinbackend` )
VALUES ( 
NULL , '1', 'helloworld', 'helloworld.php', '', 'Hello World', '1');

At this point, you can just copy and paste the above into the installer located under 'Module Management' in the
admin folder, however let me explain how the install code works..


This SQL tells Swanson CMS how to deal with the module.
ID should auto increment and can be left blank.
Since our Hello World module does not use other modules categories, it needs its own. Therefore needscat should be 1
tag is the item sent to view.php which tells it what file to load from the modules directory
load is the file to be loaded from the modules directory
adminload is the file to be loaded into the admin backend (for configuring the module, not needed in this case)
name is the module name, in this instance set to Hello World
showinbackend tells the admin Control Panel whether it should display the module. It should be set to 1, or 0 depending 
if there is an adminload file.
It's actually quite simple.


So if you run this SQL code, the module should now be visible in the category list. Create and publish a category that 
will work with hello world.
Now go to the sidebar module and add Hello World to the sidebar. View the website, and click the category and you 
should see the contents of helloworld.php located in the modules folder.


/////////////////////////////////// Multiple Pages Modules ////////////////////////////////////////////////
The Page Module that comes with Swanson CMS is useful. But say for example, you would like some
page categories to be displayed in list view and some page categories to display in blog view.
Fortunately the page module can be adapted to run multiple versions alongside each other, using the same
admin and frontend files. To do this, all you need to do is insert the following into the module installer


INSERT INTO `modules` VALUES ('', 1, 'page2', 'pages.php', 'writepage.php?type=page2', 'Pages 2', 1);

You can then add the module categories, pages, and to the sidebar, and it will work like an independant module.





